package br.com.sistema.view.lookups;

import br.com.sistema.buttons.LookupButton;
import br.com.sistema.buttons.LookupResultButton;
import br.com.sistema.controllers.EstadoLookupController;
import br.com.sistema.models.Estado;
import br.com.sistema.models.Pais;
import br.com.sistema.views.IView;

import com.vaadin.data.Container;
import com.vaadin.data.util.BeanContainer;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

public class EstadoLookupView extends AbstractLookupView implements IView {

	private static final long serialVersionUID = 1L;

	@SuppressWarnings("unused")
	private EstadoLookupController controller;
	
	private Pais pais;
	private TextField estanome = new TextField();
	private Button lookuppais = new LookupButton();
	private Button paisnome = new LookupResultButton();
	private Button pesquisa = new Button("Pesquisar");
	
	private Container beanContainer = 
			new BeanContainer<Integer, Estado>(Estado.class);
	
	public EstadoLookupView(EstadoLookupController controller) {
		
		this.controller = controller;
		estanome.setWidth("440");
		
		init();
		
		setCaption("Pesquisar Estado");
		setHeight("400");
	}

	@Override
	public Object[] getVisibleColumns() {
		return new Object[]{"estanome"};
	}

	@Override
	public String[] getColumnHeaders() {
		return new String[]{"Nome"};
	}

	@SuppressWarnings("unchecked")
	@Override
	public BeanContainer<Integer, Estado> getBeanContainer() {
		return (BeanContainer<Integer, Estado>) beanContainer;
	}

	@Override
	public Component getSearchArea() {
		
		HorizontalLayout h0 = new HorizontalLayout();
		h0.setSpacing(true);
		h0.addComponent(new Label("Pais"));
		h0.addComponent(lookuppais);
		h0.addComponent(paisnome);
		
		HorizontalLayout h1 = new HorizontalLayout();
		h1.setSpacing(true);
		h1.addComponent(new Label("Nome"));
		h1.addComponent(estanome);
		
		VerticalLayout v0 = new VerticalLayout();
		v0.setSpacing(true);
		v0.addComponent(h0);
		v0.addComponent(h1);
		v0.addComponent(pesquisa);
		
		return v0;
	}
	
	public Pais getPais() {
		return pais;
	}

	public void setPais(Pais pais) {
		this.pais = pais;
	}

	public TextField getEstanome() {
		return estanome;
	}

	public Button getLookuppais() {
		return lookuppais;
	}

	public Button getPaisnome() {
		return paisnome;
	}

	public Button getPesquisa() {
		return pesquisa;
	}

	@Override
	public Window getView() {
		return this;
	}

}
